package com.hopes.bizz.poll.statistic.controller;

import cn.hutool.extra.spring.SpringUtil;
import com.hopes.bizz.poll.alarm.service.PollAlarmStatisticsService;
import com.hopes.bizz.poll.gis.dto.GisMonitorHisDTO;
import com.hopes.bizz.poll.om.service.MonitorHisService;
import com.hopes.bizz.poll.om.service.PollRtDataService;
import com.hopes.bizz.poll.statistic.service.GISService;
import com.hopes.boss.common.core.util.R;
import com.hopes.boss.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author daijie
 * @version 1.0
 * @date 2023/6/6 15:14
 * @Description:
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/gis")
@Tag(description = "gis", name = "查询gis信息")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class GISController {

    private final GISService gisService;
    private final PollRtDataService pollRtDataService;
    private final PollAlarmStatisticsService pollAlarmStatisticsService;

    /**
     * gis信息统计
     *
     * @return R
     */
    @Operation(summary = "gis信息统计", description = "gis信息统计")
    @SysLog("gis信息统计")
    @GetMapping("/info")
    @PreAuthorize("@pms.hasPermission('poll_gis_info_view')")
    public R getGISInfo() {
        return R.ok(gisService.getGISInfo());
    }


    /**
     * Gis大气监测数值
     *
     * @return
     */
    @Operation(summary = "Gis大气监测数值", description = "Gis大气监测数值")
    @GetMapping("/gisAirMonitor")
    @PreAuthorize("@pms.hasPermission('poll_rtData_view')")
    public R gisAirMonitor() {
        return R.ok(pollRtDataService.queryGisAirMonitor());
    }


    /**
     * Gis大气监测数值
     *
     * @return
     */
    @Operation(summary = "Gis大气监测数值", description = "Gis大气监测数值")
    @GetMapping("/gisWaterMonitor")
    @PreAuthorize("@pms.hasPermission('poll_rtData_view')")
    public R gisWaterMonitor() {
        return R.ok(pollRtDataService.queryGisWaterMonitor());
    }
    /**
     * Gis大气监测污染热力图历史回溯
     *
     * @return
     */
    @Operation(summary = "Gis大气监测污染热力图历史回溯", description = "Gis大气监测污染热力图历史回溯")
    @GetMapping("/gisAirMonitorHis")
    @PreAuthorize("@pms.hasPermission('poll_his_view')")
    public R gisAirMonitorHis(@Validated GisMonitorHisDTO gisMonitorHisDTO) {
        return R.ok(SpringUtil.getBean(gisMonitorHisDTO.getDataType(), MonitorHisService.class).queryGisAirMonitorHis(gisMonitorHisDTO));
    }

    /**
     * Gis水环境监测污染热力图历史回溯
     *
     * @return
     */
    @Operation(summary = "Gis水环境监测污染热力图历史回溯", description = "Gis大气监测污染热力图历史回溯")
    @GetMapping("/gisWaterMonitorHis")
    @PreAuthorize("@pms.hasPermission('poll_his_view')")
    public R gisWaterMonitorHis(@Validated GisMonitorHisDTO gisMonitorHisDTO) {
        return R.ok(SpringUtil.getBean(gisMonitorHisDTO.getDataType(), MonitorHisService.class).queryGisWaterMonitorHis(gisMonitorHisDTO));
    }


    /**
     * Gis大气监测污染热力图实时数据
     *
     * @return
     */
    @Operation(summary = "Gis大气监测污染热力图实时数据", description = "Gis大气监测污染热力图实时数据")
    @GetMapping("/gisAirMonitorRt")
    @PreAuthorize("@pms.hasPermission('poll_rtData_view')")
    public R gisAirMonitorRt() {
        return R.ok(pollRtDataService.gisAirMonitorRt());
    }

    /**
     * gis 报警信息统计
     *
     * @return R
     */
    @Operation(summary = "gis报警信息统计", description = "gis报警信息统计")
    @SysLog("gis报警信息统计")
    @GetMapping("/gisAlarmByMainType/{mainType}")
    @PreAuthorize("@pms.hasPermission('poll_gis_info_view')")
    public R gisAlarmByMainType(@PathVariable("mainType") Integer mainType) {
        return R.ok(pollAlarmStatisticsService.getGisAlarmByMainType(mainType));
    }

    /**
     * gis 监控点数量总览
     *
     * @return R
     */
    @Operation(summary = "gis监控点数量总览", description = "gis监控点数量总览")
    @SysLog("gis监控点数量总览")
    @GetMapping("/gisSiteOverviewByMainType/{mainType}")
    @PreAuthorize("@pms.hasPermission('poll_gis_info_view')")
    public R gisSiteOverviewByMainType(@PathVariable("mainType") Integer mainType) {
        return R.ok(gisService.gisSiteOverviewByMainType(mainType));
    }

    /**
     * gis 通过监控点大类查询展示因子
     *
     * @return R
     */
    @Operation(summary = "通过监控点大类查询展示因子", description = "通过监控点大类查询展示因子")
    @GetMapping("/getDisplayFactorByMonitorTypeMain/{monitorTypeMain}")
    @PreAuthorize("@pms.hasPermission('poll_gis_info_view')")
    public R getDisplayFactorByMonitorTypeMain(@PathVariable("monitorTypeMain") Integer monitorTypeMain) {
        return R.ok(gisService.getDisplayFactorByMonitorTypeMain(monitorTypeMain));
    }
}

